<?php
/**
 * 门店管理
 *
 * @copyright   Copyright 2011, Richie
 * @author      Richie <richbossman@163.com>
 * @package     SMS
 * @link        http://www.letphp.com
 * 
 * $Id: DeptAction.class.php 74 2011-04-07 11:28:47Z 442767452@qq.com $
 */
class DeptAction extends SMSAction {
	
	function _button_dept_add(){
		return array('index');
	}
	
	function _button_dept_edit(){
		return array('index', 'add');
	}
	
	function _button_dept_index(){
		return array('add');
	}
	
	function _before_index(){

	}
	
	function _before_add(){
		$this->assign('province', D('Region', 'system')->getList());
	}
	
	function _before_edit(){
		$this->assign('province', D('Region', 'system')->getList());
		$vo = D('Dept')->getByid($_GET['id']);
		$this->assign('city', D('Region', 'system')->getList($vo['province']));
		$this->assign('district', D('Region', 'system')->getList($vo['city']));
	}
	
	//列表json
	function lst(){
		$result = array();
		$where = "";
		$this->datagrid['sort'] = isset($_REQUEST['sort']) ? 'n.'.trim($_REQUEST['sort']) : 'n.sort';
		$result['total'] = M()->table(C('DB_PREFIX').'dept AS n')->where($where)->count();
		$result['rows'] = M()->table(C('DB_PREFIX').'dept AS n')->field('n.id, n.name, n.tel, n.phone, n.contact_name, n.sort, n.add_time, n.remark')
				->page($this->datagrid['page'])
				->limit($this->datagrid['rows'])
				->order($this->datagrid['sort'].' '.$this->datagrid['order'])
				->where($where)
				->findAll();
		foreach ($result['rows'] as $key=>$row){
			$result['rows'][$key]['add_time'] = date('Y-m-d H:i', $row['add_time']);
		}
		$this->ajaxReturn('', $result);
	}
	
	//门店列表
	function dept_list(){
		$dept = M('dept')->where('parent_id=0')->order('sort ASC, id DESC')->getField('id,name');
		return $dept;
	}
}
?>